import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * @Author YuanYuan
 * @Date 2022/6/16
 * @Time 22:57
 */
public class TestJDBCDelete {

    public static void main(String[] args) throws SQLException {
        DataSource dataSource = new MysqlDataSource();

        ((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("111111");

        Connection connection = dataSource.getConnection();

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要删除的id:");
        int id = scanner.nextInt();

        String sql = "delete from student where id = ?";
        PreparedStatement statement = connection.prepareStatement(sql);
        statement.setInt(1,id);
        System.out.println(statement);

        int ret =statement.executeUpdate();
        System.out.println(ret);
        statement.close();
        connection.close();





    }
}
